#ifndef _RSSPARSER_H_
#define _RSSPARSER_H_
#include "RssStore.h"

#define RSS_FAST_EXIT

#ifdef RSS_FAST_EXIT
extern short fast_exit;
#endif
int StartElement(void *UserData, const XMLCH *uri, const XMLCH *localName, const XMLCH *qName, LPXMLVECTOR atts);
int EndElement(void *UserData, const XMLCH *uri, const XMLCH *localName, const XMLCH *qName);
int Characters(void *UserData, const XMLCH *Chars, int cbChars);
void ErrorHandler(LPXMLPARSER parser);
int cstream(BYTE *buf, int cBytes, int *cBytesActual, void *inputData);

/* stack macros (from xmldef.h) */
#define STACK_PUSH(stack,item) (XMLVector_Append((stack), (item)))
#define STACK_PEEK(stack) (XMLVector_Get((stack),(stack)->length-1))
#define STACK_REMOVE(stack) (XMLVector_Remove((stack), (stack)->length-1))
#define STACK_POP(stack,item) \
( ((stack)->length) ? (memcpy((item), STACK_PEEK((stack)), (stack)->itemSize), \
STACK_REMOVE((stack)), (item)) : NULL)

#define ASSERT_MEM_ABORT(p) if (!(p)) { printf("Out of memory! Line: %d\n", __LINE__); return XML_ABORT; }

#define		NONE			1
#define		RSS				2
#define		RSS_CHANNEL		3
#define		RSS_ITEM		4
#define		RSS_TITLE		5
#define		RSS_TIME		6
#define		RSS_DESCRIPTION	7
#define		RSS_URL			8
#define		RSS_UNKNOW		9

//enum tagSTATES { NONE, RSS, RSS_CHANNEL, RSS_ITEM, RSS_TITLE, RSS_TIME, RSS_DESCRIPTION, RSS_URL, RSS_UNKNOW} STATES;

#define	RSS_NONE	0
#define	RSS_V2		1
#define	RSS_V1		2
#define	RSS_ATOM	3
//enum rssVERSION { RSS_NONE, RSS_V2, RSS_V1, RSS_ATOM} VERSIONS;

typedef struct tagRSSPARSER {
	LPXMLPARSER parser;
	XMLSTRINGBUF textBuf;
	LPXMLVECTOR stateStack;
	int rss_version;
	int state;
	int inContent;
	int inMixedContent;
	int find_item;
	LPXMLVECTOR stories;
	RSSFeedItem *curStory;
} RSSPARSER;
#endif
